
#ifndef OBSERVER_HPP
#define OBSERVER_HPP

/*
 * Classes for the Observer Pattern.
 *
 * author Gerry Gaboury
 * $Id: Observer.hpp 2 2012-05-22 17:55:16Z gerry@gaboury.biz $
 */

#include <set>
#include <map>
#include <string>

using namespace std;

class ObserverSubject;

class Observer
{
protected:
  ObserverSubject* m_subject;
public:
  Observer ( ObserverSubject* p_subject );
  //Observer ();
  virtual ~Observer();
  //virtual void subject ( ObserverSubject* p_subject );
  virtual void detach();
  virtual void update () = 0;
};

typedef set<Observer*>                        ObserverSet;
typedef ObserverSet::iterator                 ObserverSetIter;

typedef map<string,string>                    StringMap;
typedef map<string,string>::iterator          StringMapIter;
typedef map<string,string>::const_iterator    StringMapCIter;

class ObserverSubject
{
private:
  ObserverSet m_observers;
public:
  // default constructor is OK but need to define a destructor
  virtual ~ObserverSubject();
  virtual void attach ( Observer* p_observer );
  virtual void detach ( Observer* p_observer );
  virtual void notify ();
  //virtual const StringMap& state () = 0;
  //virtual void state ( const StringMap& p_state ) = 0;
};

#endif // OBSERVER_HPP
